class Tools {
  static formatDate(date: Date | number, format: string = 'yyyy-MM-dd hh:mm:ss'): string {
    let info = date as Date
    if (typeof date === 'number') {
      info = new Date()
      info.setTime(date)
    }
    // 格式化日期为字符串
    const year = info.getFullYear()
    const month = info.getMonth() + 1
    const day = info.getDate()
    const hour = info.getHours()
    const minute = info.getMinutes()
    const second = info.getSeconds()
    let result = format.replace('yyyy', year + '')
    result = result.replace('MM', month < 10 ? '0' + month : month + '')
    result = result.replace('dd', day < 10 ? '0' + day : day + '')
    result = result.replace('hh', hour < 10 ? '0' + hour : hour + '')
    result = result.replace('mm', minute < 10 ? '0' + minute : minute + '')
    result = result.replace('ss', second < 10 ? '0' + second : second + '')
    return result
  }

  //@ts-expect-error js无法确定类型
  static concatJson(...jsons) {
    let result = {}
    for (const json of jsons) {
      result = Object.assign(result, json)
    }
    return result
  }
}

export { Tools }
